package club.baimahu.pencil;

import club.baimahu.pencil.domain.entity.CommonBuyer;
import club.baimahu.pencil.domain.entity.SuperMarketBuilder;
import club.baimahu.pencil.domain.session.Supermarket;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;

/**
 * 建造者模式，将超市的创建和表现分离，只要声明式的设置超市预期的状态，不需要参与复杂的创建过程，创建过程由Builder负责
 */
public class Story2 {
    static Logger logger = LoggerFactory.getLogger(Story2.class);

    public static void main(String[] args) {
        CommonBuyer buyer = new CommonBuyer("小刚");
        buyer.addCacheAccount("000030000009999",new BigDecimal(100));

        String cacheAccount = "1111111100003632";

        SuperMarketBuilder superMarketBuilder = new SuperMarketBuilder();
        Supermarket supermarket = superMarketBuilder.province("浙江省")
                .city("杭州市")
                    .region("滨江区")
                        .detailAddress("长河街道江陵路111号")
                                .cacheAccount(cacheAccount,new BigDecimal(1000))
                                        .build("联华超市-滨江分店");

        buyer.startShopping(supermarket);

        logger.info("supermarket address = {}",supermarket.getAddress());

        buyer.buy("NO001",supermarket);
        buyer.buy("NO002",supermarket );
        buyer.buy("NO003" ,supermarket);

        for(int j = 0 ; j <20 ; j++){
            buyer.buy("NO002",supermarket);
        }

        buyer.leave(supermarket);

    }
}
